package com.recruit.common.http;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 陈竞超
 * @version 1.0
 * @qq 2250537249
 */
public class HttpTemplate {
    private static final RestTemplate restTemplate = new RestTemplate();

    public static <T> T httpPost(String url, Map<String, Object> jobData, Map<String, Object> resumeData, Class<T> responseType) {
        // 创建请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);

        // 构造请求数据
        Map<String, Object> requestBody = new HashMap<>();
        requestBody.put("job_data", jobData);
        requestBody.put("resume_data", resumeData);

        // 发送请求
        HttpEntity<Map<String, Object>> request = new HttpEntity<>(requestBody, headers);
        return restTemplate.postForObject(url, request, responseType);
    }
}